////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////find and install needed commands.
//////follow instructions that come up to install:
//////command for recoding variables to 0-1 interval
findit _gstd01
//////quick standardization command (zval):
findit zval

//////KEY TO WAVES/PANELS:
***WAVES.
///1 --> (B)aseline: December 2007
///2 --> (J)anuary 2008
///3 --> (M)arch 2008
///4 --> (S)eptember 2008
///5 --> (O)ctober 2008
///6 --> (P)ost-election 2008

//////was respondent in first wave?
gen orig=1 if BDISP==1
replace orig=0 if BDISP~=1

//////Generate state indicator:
gen state=PROFILE66

//////Generate age:
gen age2008=2008-PROFILE51

//////Generate income:
gen rinc=PROFILE59 if PROFILE59<15
egen rinc01=std01(rinc)

//////Generate gender:
recode PROFILE54 (1=1) (2=0), generate(rsex)

//////Generate education:
recode PROFILE57 (1=0) (2=1) (3=2) (4=2) (5=3) (6=4), generate(reduc)
egen reduc01=std01(reduc)

//////race indicators:
gen rblack=0 if PROFILE55~=2
gen rlat=0 if PROFILE55~=3
replace rblack=1 if PROFILE55==2
replace rlat=1 if PROFILE55==3

//////TIPI / Big Five:
gen rPROFILE41=(7-PROFILE41)/6
gen rPROFILE43=(7-PROFILE43)/6
gen rPROFILE45=(7-PROFILE45)/6
gen rPROFILE47=(7-PROFILE47)/6
gen rPROFILE49=(7-PROFILE49)/6
gen rPROFILE40=(PROFILE40-1)/6
gen rPROFILE42=(PROFILE42-1)/6
gen rPROFILE44=(PROFILE44-1)/6
gen rPROFILE46=(PROFILE46-1)/6
gen rPROFILE48=(PROFILE48-1)/6
///extraversion:
egen rex=rmean(rPROFILE40 rPROFILE45)
///agreeableness:
egen rag=rmean(rPROFILE41 rPROFILE46)
///conscientiousness:
egen rcsc=rmean(rPROFILE47 rPROFILE42)
///emotional stability:
egen res=rmean(rPROFILE43 rPROFILE48)
///openness to experience:
egen rop=rmean(rPROFILE44 rPROFILE49)

//////ideology in waves 1-5:
gen rideo1=(BCAP700s-1)/4 if BCAP700s<6
gen rideo2=(JCAP700s-1)/4 if JCAP700s<6
gen rideo3=(MCAP700S-1)/4 if MCAP700S<6
gen rideo4=(SCAP700S-1)/4 if SCAP700S<6
gen rideo5=(OCAP700S-1)/4 if OCAP700S<6

//////party identification in waves 1-5:
gen rpid1=(BCAP8-1)/6 if BCAP8<8
gen rpid2=(JCAP8-1)/6 if JCAP8<8
gen rpid3=(MCAP8-1)/6 if MCAP8<8
gen rpid4=(SCAP8-1)/6 if SCAP8<8
gen rpid5=(OCAP8-1)/6 if OCAP8<8

//////evaluative difference variables:
///Obama:
recode OCAP300O (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(tho5)
recode SCAP300O (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(tho4)
recode MCAP300O (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(tho3)
recode JCAP300O (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(tho2)
recode BCAP300BO (4=0) (3=1) (0=2) (2=3) (2=4) (5=.), generate(tho1)
///McCain:
recode OCAP300JM (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(jmc5)
recode SCAP300JM (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(jmc4)
recode MCAP300JM (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(jmc3)
recode JCAP300JM (4=0) (3=1) (0=2) (1=3) (2=4) (5=.), generate(jmc2)
recode BCAP300JM (4=0) (3=1) (0=2) (2=3) (2=4) (5=.), generate(jmc1)
///differences:
gen prdiff5=jmc5-tho5
gen prdiff4=jmc4-tho4 
gen prdiff3=jmc3-tho3 
gen prdiff2=jmc2-tho2
gen prdiff1=jmc1-tho1
egen prdiff501=std01(prdiff5)
egen prdiff401=std01(prdiff4)
egen prdiff301=std01(prdiff3) 
egen prdiff201=std01(prdiff2)
egen prdiff101=std01(prdiff1)

//////trust difference variables:
///Obama:
recode OCAP901O (9=.), generate(tro5)
recode SCAP901O (9=.), generate(tro4)
recode MCAP901O (9=.), generate(tro3)
recode JCAP901O (9=.), generate(tro2)
recode BCAP901O (9=.), generate(tro1)
///McCain:
recode OCAP901M (9=.), generate(trm5)
recode SCAP901M (9=.), generate(trm4)
recode MCAP901M (9=.), generate(trm3)
recode JCAP901M (9=.), generate(trm2)
recode BCAP901M (9=.), generate(trm1)
///differences:
gen trdiff5=trm5-tro5 
gen trdiff4=trm4-tro4
gen trdiff3=trm3-tro3 
gen trdiff2=trm2-tro2
gen trdiff1=trm1-tro1 
egen trdiff501=std01(trdiff5)
egen trdiff401=std01(trdiff4)
egen trdiff301=std01(trdiff3) 
egen trdiff201=std01(trdiff2)
egen trdiff101=std01(trdiff1)

//////strong leader difference:
///Obama:
recode SCAP900O (9=.), generate(slo4)
recode MCAP900O (9=.), generate(slo3)
recode JCAP900O (9=.), generate(slo2)
recode BCAP900O (9=.), generate(slo1)
///McCain:
recode SCAP900M (9=.), generate(slm4)
recode MCAP900M (9=.), generate(slm3)
recode JCAP900M (9=.), generate(slm2)
recode BCAP900M (9=.), generate(slm1)
///differences:
gen sldiff4=slm4-slo4 
gen sldiff3=slm3-slo3
gen sldiff2=slm2-slo2 
gen sldiff1=slm1-slo1
egen sldiff401=std01(sldiff4)
egen sldiff301=std01(sldiff3) 
egen sldiff201=std01(sldiff2)
egen sldiff101=std01(sldiff1)

//////standardizations:		
zval rex rag rcsc res rop, pre(z)
zval rideo1 rpid1, pre(z)
zval rideo2 rpid2, pre(z)
zval rideo3 rpid3, pre(z)
zval rideo4 rpid4, pre(z)
zval rideo5 rpid5, pre(z)
zval prdiff501 prdiff401 prdiff301 prdiff201 prdiff101, pre(z)
zval trdiff501 trdiff401 trdiff301 trdiff201 trdiff101, pre(z)
zval sldiff401 sldiff301 sldiff201 sldiff101, pre(z)
		
//////set survey weights and clustering:
svyset state [pweight=psweight]
		
//////(1) Do Political Attitudes Evolve Across Campaigns as a Function of Personality?
///Table 1, without standardization of key variables.
svy: reg rpid5 i.state rpid1 age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 
estimates store dv1
svy: reg rideo5 i.state rideo1 age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 
estimates store dv2
svy: reg prdiff501 i.state prdiff101 age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 
estimates store dv3
svy: reg trdiff501 i.state trdiff101 age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 
estimates store dv4
svy: reg sldiff401 i.state sldiff101 age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 
estimates store dv5
suest dv1 dv2 dv3 dv4 dv5, svy

///Table A1, with standardization of key variables.
svy: reg zrpid5 i.state zrpid1 age2008 rinc01 rsex reduc01 rblack rlat zrex zrag zrcsc zres zrop if orig==1 & PROFILE65==1 
estimates store dv1
svy: reg zrideo5 i.state zrideo1 age2008 rinc01 rsex reduc01 rblack rlat zrex zrag zrcsc zres zrop if orig==1 & PROFILE65==1 
estimates store dv2
svy: reg zprdiff501 i.state zprdiff101 age2008 rinc01 rsex reduc01 rblack rlat zrex zrag zrcsc zres zrop if orig==1 & PROFILE65==1 
estimates store dv3
svy: reg ztrdiff501 i.state ztrdiff101 age2008 rinc01 rsex reduc01 rblack rlat zrex zrag zrcsc zres zrop if orig==1 & PROFILE65==1 
estimates store dv4
svy: reg zsldiff401 i.state zsldiff101 age2008 rinc01 rsex reduc01 rblack rlat zrex zrag zrcsc zres zrop if orig==1 & PROFILE65==1 
estimates store dv5
suest dv1 dv2 dv3 dv4 dv5, svy

//////(2) Do Political Identities Mediate the Effects of Personality on Campaign-Specific Attitudes?
///evaluations.
svy: sem (prdiff501 <- rpid4 rideo4 prdiff401 rex rag rcsc res rop) ///
	(prdiff401 <- rpid3 rideo3 prdiff301 rex rag rcsc res rop) ///
	(prdiff301 <- rpid2 rideo2 prdiff201 rex rag rcsc res rop) ///
	(prdiff201 <- rpid1 rideo1 prdiff101 rex rag rcsc res rop) ///
	(rpid5 <- rpid4) ///
	(rpid4 <- rpid3) ///
	(rpid3 <- rpid2) ///
	(rpid2 <- rpid1 rex rag rcsc res rop) ///
	(rideo5 <- rideo4) ///
	(rideo4 <- rideo3) ///
	(rideo3 <- rideo2) ///
	(rideo2 <- rideo1 rex rag rcsc res rop) if orig==1 & PROFILE65==1
estat gof, stats(chi2 rmsea res indices)
estat teffects, compact
estat teffects, stand compact
///trust.
svy: sem (trdiff501 <- rpid4 rideo4 trdiff401 rex rag rcsc res rop) ///
	(trdiff401 <- rpid3 rideo3 trdiff301 rex rag rcsc res rop) ///
	(trdiff301 <- rpid2 rideo2 trdiff201 rex rag rcsc res rop) ///
	(trdiff201 <- rpid1 rideo1 trdiff101 rex rag rcsc res rop) ///
	(rpid5 <- rpid4) ///
	(rpid4 <- rpid3) ///
	(rpid3 <- rpid2) ///
	(rpid2 <- rpid1 rex rag rcsc res rop) ///
	(rideo5 <- rideo4) ///
	(rideo4 <- rideo3) ///
	(rideo3 <- rideo2) ///
	(rideo2 <- rideo1 rex rag rcsc res rop) if orig==1 & PROFILE65==1 
estat gof, stats(chi2 rmsea res indices)
estat teffects, compact
estat teffects, stand compact
///leadership.
svy: sem (sldiff401 <- rpid4 rideo4 sldiff301 rex rag rcsc res rop) ///
	(sldiff301 <- rpid3 rideo3 sldiff201 rex rag rcsc res rop) ///
	(sldiff201 <- rpid2 rideo2 sldiff101 rex rag rcsc res rop) ///
	(rpid4 <- rpid3) ///
	(rpid3 <- rpid2) ///
	(rpid2 <- rpid1 rex rag rcsc res rop) ///
	(rideo4 <- rideo3) ///
	(rideo3 <- rideo2) ///
	(rideo2 <- rideo1 rex rag rcsc res rop) if orig==1 & PROFILE65==1
estat gof, stats(chi2 rmsea res indices)
estat teffects, compact
estat teffects, stand compact

//////(3) Do Campaigns Strengthen the Predictive Power of Personality?
///Table A2: party:
svy: reg rpid1 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & rpid1~=.
estimates store pty1
svy: reg rpid5 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & rpid1~=.
estimates store pty5
suest pty1 pty5, svy

///Table A2: ideology.
svy: reg rideo1 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & rideo1~=.
estimates store id1
svy: reg rideo5 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & rideo1~=.
estimates store id5
suest id1 id5, svy

///Table 3.
///December 2007 (prdiff101 etc) and Sept/Oct 2008 (prdiff501 etc) estimates used for Table 3.
///March 2008 estimates (for prdiff301, trdiff301, sldiff301) are used for Footnote 9.
//affect: increase in predictive power.
svy: reg prdiff101 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & prdiff101~=.
estimates store pd1
svy: reg prdiff501 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & prdiff101~=.
estimates store pd5
suest pd1 pd5, svy
test [pd1]rcsc = [pd5]rcsc
test [pd1]res = [pd5]res
test [pd1]rop = [pd5]rop

svy: reg prdiff301 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & prdiff101~=.
estimates store pd3

///trustworthy: increase in predictive power.
svy: reg trdiff101 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & trdiff101~=.
estimates store tr1
svy: reg trdiff501 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & trdiff101~=. 
estimates store tr5
suest tr1 tr5, svy
test [tr1]rcsc = [tr5]rcsc
test [tr1]res = [tr5]res
test [tr1]rop = [tr5]rop

svy: reg trdiff301 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & trdiff101~=.
estimates store tr3

///strong leader: increase in predictive power.
svy: reg sldiff101 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & sldiff101~=. 
estimates store sl1
svy: reg sldiff401 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & sldiff101~=. 
estimates store sl4
suest sl1 sl4, svy
test [sl1]rcsc = [sl4]rcsc
test [sl1]res = [sl4]res
test [sl1]rop = [sl4]rop

svy: reg sldiff301 i.state age2008 rinc01 rsex reduc01 rblack rlat rex rag rcsc res rop if orig==1 & PROFILE65==1 & sldiff101~=. 
estimates store sl3

